home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Tools / Languages / MacGofer 0.22d / MacGofer Sources / connect.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-01-06  |  9.5 KB  |  246 lines  |  [TEXT/MPS ]

  1. /* --------------------------------------------------------------------------
  2.  * connect.h:    Copyright (c) Mark P Jones 1991-1993.   All rights reserved.
  3.  *        See goferite.h for details and conditions of use etc...
  4.  *        Gofer version 2.28 January 1993
  5.  *
  6.  * Connections between components of the Gofer system
  7.  * ------------------------------------------------------------------------*/
  8.  
  9. /* --------------------------------------------------------------------------
  10.  * Standard data:
  11.  * ------------------------------------------------------------------------*/
  12.  
  13. extern Name  nameFalse,   nameTrue;    /* primitive constructor functions */
  14. extern Name  nameNil,     nameCons;
  15. extern Name  nameFatbar,  nameFail;    /* primitives reqd for translation */
  16. extern Name  nameIf,      nameSel;
  17. extern Name  nameMinus,      nameDivide;
  18. extern Name  nameUndefMem;         /* undefined member primitive       */
  19. extern Name  nameError;            /* for runtime error messages       */
  20. extern Name  nameBlackHole;        /* for GC-detected black hole       */
  21. extern Name  nameAnd,      nameOr;    /* for optimisation of && and ||   */
  22. extern Name  nameOtherwise;
  23.  
  24. extern Name  nameResult,  nameBind;    /* for translation of monad comps  */
  25. extern Name  nameZero;
  26.  
  27. extern Name  namePrint;            /* printing primitive           */
  28.  
  29. extern Name  nameReadFile,   nameWriteFile;/* I/O name primitives       */
  30. extern Name  nameAppendFile, nameReadChan;
  31. extern Name  nameAppendChan, nameEcho;
  32. extern Name  nameGetArgs,    nameGetProgName;
  33. extern Name  nameGetEnv;
  34. extern Name  nameSuccess,    nameStr;
  35. extern Name  nameFailure,    nameStrList;
  36. extern Name  nameWriteError;
  37. extern Name  nameReadError,  nameSearchError;
  38. extern Name  nameFormatError,nameOtherError;
  39.  
  40. #ifdef LAMBDAVAR
  41. extern Name  nameVar;            /* internal lambda var constructor */
  42. extern Type  typeProg;            /* type of a lambda var program       */
  43. extern Void  lvExecute    Args((Cell));    /* lambda var executor           */
  44. #endif
  45. #ifdef LAMBDANU
  46. extern Name nameTag;            /* internal lambda nu constructor  */
  47. extern Type typeLnProg;            /* type of a lambda nu prog       */
  48. extern Void lnExecute   Args((Cell));    /* Lambda nu executor           */
  49. #endif
  50.  
  51. extern Text  textPlus,    textMult;    /* used to recognise n+k/c*n pats  */
  52.  
  53. extern String repeatStr;        /* repeat last command string       */
  54.  
  55. extern Type  typeString;        /* String  == [Char]           */
  56. extern Type  typeDialogue;        /* Dialogue== [Response]->[Request]*/
  57.  
  58. extern Cell  *CStackBase;        /* pointer to base of C stack       */
  59.  
  60. extern List  tyconDefns;        /* list of type constructor defns  */
  61. extern List  typeInDefns;        /* list of synonym restrictions       */
  62. extern List  valDefns;            /* list of value definitions       */
  63. extern List  opDefns;            /* list of operator definitions    */
  64. extern List  classDefns;        /* list of class definitions       */
  65. extern List  instDefns;            /* list of instance definitions    */
  66. extern List  overDefns;            /* list of overloaded member defns */
  67. extern Cell  inputExpr;            /* evaluator input expression      */
  68. extern Addr  inputCode;            /* Code for compiled input expr    */
  69.  
  70. extern Int   whnfArgs;            /* number of args of term in whnf  */
  71. extern Cell  whnfHead;            /* head of term in whnf            */
  72. extern Int   whnfInt;            /* integer value of term in whnf   */
  73. extern Float whnfFloat;            /* float value of term in whnf       */
  74. extern Long  numReductions;        /* number of reductions used       */
  75. extern Long  numCells;            /* number of cells allocated       */
  76. extern Int   numberGcs;            /* number of garbage collections   */
  77.  
  78. extern Bool  gcMessages;        /* TRUE => print GC messages       */
  79. extern Bool  literateScripts;        /* TRUE => default lit scripts     */
  80. extern Bool  literateErrors;        /* TRUE => report errs in lit scrs */
  81. extern Bool  useConformality;        /* TRUE => check patbind conform'ty*/
  82. extern Bool  anyEvidence;        /* TRUE => don't search for best ev*/
  83. extern Bool  coerceNumLiterals;        /* TRUE => insert fromInteger calls*/
  84.                     /*       etc for numeric literals*/
  85. extern Bool  andorOptimise;        /* TRUE => optimise uses of &&, || */
  86. extern Bool  showDicts;            /* TRUE => show dictionary params  */
  87.                     /*       in output expressions   */
  88. extern Bool  catchAmbigs;        /* TRUE => functions with ambig.   */
  89.                     /*       types produce error       */
  90. extern Bool  failOnError;        /* TRUE => error produces immediate*/
  91.                     /*       termination           */
  92.  
  93. extern Int   maxEvidLevel;        /* maximum no of selects in evid   */
  94. extern Bool  silentEvFail;        /* TRUE => keep quiet if maxEvidLev*/
  95.                     /*        is exceeded.           */
  96.  
  97. extern Bool  kindExpert;        /* TRUE => display kind errors in  */
  98.                     /*        full detail           */
  99. extern Bool  overSingleton;        /* TRUE => overload singleton list */
  100.                     /*       notation, [x]       */
  101. extern Bool  traceEval;            /* TRUE => trace evaluation */
  102.  
  103. /* --------------------------------------------------------------------------
  104.  * Function prototypes etc...
  105.  * ------------------------------------------------------------------------*/
  106.  
  107. extern Void   everybody        Args((Int));
  108.  
  109. #define RESET   1        /* reset subsystem                         */
  110. #define MARK    2        /* mark parts of graph in use by subsystem */
  111. #define INSTALL 3        /* install subsystem (executed once only)  */
  112. #define EXIT    4        /* Take action immediately before exit()   */
  113. #define BREAK   5        /* Take action after program break       */
  114. #define PRELUDE 6        /* Init. once prelude Tycons/Classes known */
  115.  
  116. typedef long   Target;
  117. extern  Void   setGoal          Args((String, Target));
  118. extern  Void   soFar            Args((Target));
  119. extern  Void   done             Args((Void));
  120. extern  String fromEnv        Args((String,String));
  121.  
  122. extern  Void   storage          Args((Int));
  123. extern  Void   setLastExpr    Args((Cell));
  124. extern  Cell   getLastExpr    Args((Void));
  125. extern    List   addNamesMatching Args((String,List));
  126.  
  127. extern  Void   input            Args((Int));
  128. extern  Void   consoleInput     Args((String));
  129. extern  Void   projInput    Args((String));
  130. extern  Void   parseScript      Args((String,Long));
  131. extern  Void   parseExp         Args((Void));
  132. extern  String readFilename     Args((Void));
  133. extern  String readLine        Args((Void));
  134. extern  Syntax defaultSyntax    Args((Text));
  135. extern  String unlexChar        Args((Char,Char));
  136.  
  137. extern  Void   staticAnalysis    Args((Int));
  138. extern  Void   tyconDefn    Args((Int,Cell,Cell,Cell));
  139. extern  Void   setTypeIns    Args((List));
  140. extern  Void   clearTypeIns    Args((Void));
  141. extern  Bool   isAmbiguous    Args((Type));
  142. extern  Void   ambigError    Args((Int,String,Cell,Type));
  143. extern  Void   classDefn    Args((Int,Cell,Cell));
  144. extern  Void   instDefn        Args((Int,Cell,Cell));
  145. extern  Void   primDefn        Args((Int,List,Cell));
  146. extern  Void   checkExp        Args((Void));
  147. extern  Void   checkDefns    Args((Void));
  148.  
  149. extern  Void   typeChecker    Args((Int));
  150. extern  Type   typeCheckExp    Args((Void));
  151. extern  Void   typeCheckDefns    Args((Void));
  152. extern  Void   insertInst    Args((Int,Class,Inst));
  153. extern  Cell   rhsExpr        Args((Cell));
  154. extern  Int    rhsLine        Args((Cell));
  155. extern  Bool   typeMatches    Args((Type,Type));
  156. extern  Bool   typeInstOf    Args((Type,Type));
  157. extern  Dict   listMonadDict    Args((Void));
  158.  
  159. extern  Void   kindTyconGroup    Args((List));
  160. extern  Void   kindClassGroup    Args((List));
  161. extern  Void   kindSigType    Args((Int,Type));
  162. extern  Void   kindInst        Args((Inst,Int));
  163.  
  164. extern  Void   compiler         Args((Cell));
  165. extern  Void   compileDefns     Args((Void));
  166. extern  Void   compileExp       Args((Void));
  167. extern  Bool   refutable    Args((Cell));
  168. extern  Int    discrArity       Args((Cell));
  169.  
  170. extern  Void   machine          Args((Int));
  171. extern  Addr   codeGen          Args((Name,Int,Cell));
  172. extern  Void   unwind           Args((Cell));
  173. extern  Void   eval             Args((Cell));
  174. extern  Cell   evalWithNoError  Args((Cell));
  175. extern  Void   evalFails        Args((StackPtr));
  176. extern  Cell   graphForExp    Args((Void));
  177.  
  178. extern  Void   builtIn          Args((Int));
  179. extern  Void   abandon        Args((String,Cell));
  180. extern  Cell   outputString    Args((FILE *,Cell,Bool));
  181. extern  Void   dialogue        Args((Cell));
  182. extern  Cell   consChar        Args((Char));
  183.  
  184. extern  Void   machdep          Args((Int));
  185. extern  String timeString    Args((Void));
  186. extern  Int    shellEsc        Args((String));
  187. extern  Int    getTerminalWidth Args((Void));
  188. extern  Void   normalTerminal    Args((Void));
  189. extern  Void   noechoTerminal    Args((Void));
  190. extern  Int    readTerminalChar Args((Void));
  191. extern  Void   gcStarted    Args((Void));
  192. extern  Void   gcScanning    Args((Void));
  193. extern  Void   gcRecovered    Args((Int));
  194. extern  Void   gcCStack        Args((Void));
  195.  
  196. /* 
  197.     C Stack overflow check -- stronger than the GC check in gcCStack().
  198.  
  199.     Most of the Gofer routines are recursive, and therefore
  200.     assume effectively infinite C stack.  This is not a
  201.     reasonable assumption on a machine without an MMU, or
  202.     on an OS which doesn't use that MMU, such as the Mac.
  203.     The routine below attempts to avoid problems by checking 
  204.     the size of the stack BEFORE the overflow occurs!  
  205.     Afterwards would be too late!!
  206.  
  207.         You may want something similar even on machines other than Macs
  208.     if you don't have memory protection or dynamically growable
  209.         stacks (for example, I'd expect the PC version to crash horribly, 
  210.     and give occasional wrong results whenever the stack overflows,
  211.     but maybe the C compilers allow for this?!).    
  212.  
  213.     KH
  214. */
  215.  
  216.  
  217. #if MPW
  218.  
  219. /*
  220.    Minimum space reserved for stack growth during recursive calls.
  221.    Allow at least enough room for mprintf -- approx 1500 bytes
  222.    are needed.
  223. */
  224.  
  225. #define STACK_HEADROOM    2048
  226.  
  227. #include <setjmp.h>
  228.  
  229. extern jmp_buf catch_error;
  230.  
  231. #if MPW
  232. #include <memory.h>
  233. #endif
  234.  
  235. #define STACK_CHECK \
  236.     { long stackleft = StackSpace();    \
  237.           if(stackleft <= STACK_HEADROOM)    \
  238.         longjmp(catch_error,25);        \
  239.     }
  240. #else
  241. #define    STACK_CHECK
  242. #endif
  243.  
  244.  
  245. /*-------------------------------------------------------------------------*/
  246.